package com.avic.common.convertor;


import com.avic.common.constant.AppConstant;
import com.avic.controller.info.FleetResourceListInfo;
import com.avic.controller.info.FleetResourceSelectInfo;
import com.avic.dal.model.CarResource;
import com.avic.dal.model.FleetResource;
import com.avic.dal.model.vo.FleetResourceListVO;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 车辆资源对象转换器
 */
public class FleetResourceConvertor {


    public static List<FleetResourceListInfo> fleetResourceListVOToFleetResourceListInfo(List<FleetResourceListVO> fleetResourceListVOS) {
        if (null != fleetResourceListVOS && fleetResourceListVOS.size() > 0) {
            List<FleetResourceListInfo> fleetResourceListInfos = new ArrayList<>();
            fleetResourceListVOS.forEach(fleetResourceListVO -> {
                FleetResourceListInfo fleetResourceListInfo = new FleetResourceListInfo();

                List<CarResource> carResources = fleetResourceListVO.getCarResourceNumbers();
                if (null != carResources && carResources.size() > 0) {
                    List<String> carNumbers = new ArrayList<>();
                    carResources.forEach(carResource -> {
                        carNumbers.add(carResource.getCarName());
                    });
                    fleetResourceListInfo.setCarResourceNumbers(carNumbers);
                }
                fleetResourceListInfo.setCreateTime(StringUtils.isNotBlank(fleetResourceListVO.getCreateTime()) ?
                        StringUtils.substringBefore(fleetResourceListVO.getCreateTime(), AppConstant.MYBATIS_DATA_TIME_SEPARATOR) : StringUtils.EMPTY);
                fleetResourceListInfo.setFleetName(fleetResourceListVO.getFleetName());
                fleetResourceListInfo.setId(fleetResourceListVO.getId());


                fleetResourceListInfos.add(fleetResourceListInfo);
            });
            return fleetResourceListInfos;
        }
        return new ArrayList<>();
    }

    public static List<FleetResourceSelectInfo> fleetResourceListToFleetResourceSelectInfo(List<FleetResource> fleetResourceList) {
        if (null != fleetResourceList && fleetResourceList.size() > 0) {
            List<FleetResourceSelectInfo> fleetResourceSelectInfos = new ArrayList<>();
            fleetResourceList.forEach(fleetResource -> {
                FleetResourceSelectInfo fleetResourceListInfo = new FleetResourceSelectInfo();
                fleetResourceListInfo.setFleetName(fleetResource.getFleetName());
                fleetResourceListInfo.setId(fleetResource.getId());
                fleetResourceSelectInfos.add(fleetResourceListInfo);
            });
            return fleetResourceSelectInfos;
        }
        return new ArrayList<>();
    }

}
